home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11751 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  958 b 

  1. Path: hops.cs.jhu.edu!lasher
  2. From: lasher@hops.cs.jhu.edu (John E. Davis)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: String Problem
  5. Date: 26 Mar 1996 05:54:43 GMT
  6. Organization: JHU computer science
  7. Message-ID: <4j80r4$9ir@blaze.cs.jhu.edu>
  8. References: <4j6l61$4no@B1FF.mindspring.com>
  9. NNTP-Posting-Host: hops.cs.jhu.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Shon Frazier (vtipres@atl.mindspring.com) expostulated:
  13. > This is supposed to be a variation on sample code from a textbook.
  14. > Can anyone tell me why NameCheck = 0 when I run the program?
  15.  
  16. > /*
  17. >    Testing character transactions.
  18. > */
  19.  
  20. > #include <stdio.h>
  21. > #include <ctype.h>
  22.  
  23. > int main()
  24. > {
  25. >    char Name[11] = "John";
  26. >    char *WhereName;
  27. >    int NameCheck = 0;
  28.  
  29. >    WhereName = Name;
  30.  
  31. >    if ( WhereName == "John" )
  32.  
  33. try using if(!(strcmp(WhereName, "John"))) instead.  remember that strcmp 
  34. returns 0 if the strings are the same so you need the ! in front.
  35.  
  36.  
  37. john davis
  38. lasher@hops.cs.jhu.edu
  39.